$(document).ready(function(){
    $.fn.dataTable.ext.errMode = 'none';
    $('#table_list').on( 'error.dt', function ( e, settings, techNote, message ) {
        $.jBox.error(GLOBAL_DATATBALE_ERROR_302, '错误');
        return false;
    } ).DataTable({
        dom: '<"top">rt<"bottom"flip><"clear">',
        language: {
            "sUrl":'../static/plugins/datatables/language.json'
        },
        "searching": false,
        "processing": true,
        "serverSide": true,
        ajax:{
            url:'/sys-log/backend-load-list',
            type:'post',
            data:function(d){
                d.service = $('#service').val();
                d.creator = $('#creator').val();
                d.dateval = $('#reservationtime').val();
                //add by allen.qiang 20171228 标题 ip 条件 start
                d.log_title = $('#log_title').val();
                d.ip = $('#ip').val();
                //add by allen.qiang 20171228 标题 ip 条件   enc
            },
            error:getError
        },
        aoColumns: [
            { "data": "id", "bSortable": true},
            { "data": "log_category_name", "bSortable":false },
            { "data": "log_title", "bSortable":false },
            { "data": "log_action", "bSortable":false },
            { "data": "content", "bSortable":false },
            { "data": "ip", "bSortable":false },
            { "data": "creator", "bSortable":false },
            { "data": "create_time", "bSortable":true }
        ],
        columnDefs: [
            {
                "targets": [0],
                "orderable":false,
                "searchable":false
            },
            {
                "targets": [4],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {
                    return '<a href="javascript:" onclick="viewInfo('+ full.id +')">' + data + '</a>';
                }
            },
        ],

        order: [[ 0, "desc" ]]                      //初始指定排序字段
    });

});


$('#reservationtime').daterangepicker({
    language:  'zh-CN',
//    timePicker: true,
//    timePickerIncrement: 30,
    format: 'YYYY/MM/DD',
    locale: {
        format: 'YYYY-MM-DD',
        daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
    }
});

$('#select_button').click(function(){
    var table = $('#table_list').DataTable();
    table.ajax.reload();

})

function viewInfo(id){
    $.ajax({
        type: "post",
        dataType: "json",
        url:'/sys-log/backend-load-info',
        data: {id:id},
        success: function (data) {
            if(data.code == 200)
            {
                $('#loginfo').val(data.val);//日志内容
                $('#myModal').modal('show');
            }
            else{
                $.jBox.error(data.val, '错误');
            }
        }
    });

}

$('#reset_button').click(function(){
	var str_date = show();
    $('#service').val('');
    $('#creator').val('');
    //mod by allen.qiang 20171228 优化操作  start
    $('#log_title').val('');
    //$('#reservationtime').val(str_date+' - '+str_date);
    $('#reservationtime').val('');
    $('#ip').val('');
    //mod by allen.qiang 20171228 优化操作    end
    var table = $('#table_list').DataTable();
    table.ajax.reload();
})

function show() {
    var date = new Date();
    var seperator1 = "-";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    return currentdate;
}


var setting = {
    view: {
        showIcon: false
    },
    data: {
        simpleData: {
            enable: true,
            idKey:"id",
            pIdKey:"pId"
        }
    }
};

var setting_other = {
    view: {
        showIcon: false
    },
    data: {
        simpleData: {
            enable: true,
            idKey:"id",
            pIdKey:"pId"
        }
    }
};